import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_uikit/t2mini/test/testpage.dart';
import 'package:flutter_uikit/t2mini/ui/trade/tradePage.dart';
import 'package:flutter_uikit/t2mini/view/IconText%20.dart';
import 'package:flutter_uikit/utils/uidata.dart';

import '../../utils/screenUtil.dart';
import 'setting/settingPage.dart';

class MyHomePage extends StatelessWidget {
  final materialApp = MaterialApp(
    debugShowCheckedModeBanner: false,
    theme: ThemeData(
      backgroundColor: Color.fromRGBO(74, 85, 124, 1),
    ),
    home: HomeAppPage(),
  );

  @override
  Widget build(BuildContext context) {
    return materialApp;
  }
}

class HomeAppPage extends StatefulWidget {
  @override
  _HomeAppPageState createState() => _HomeAppPageState();
}

class _HomeAppPageState extends State<HomeAppPage> {
  Color myColor = Color.fromRGBO(74, 85, 124, 1);

  @override
  Widget build(BuildContext context) {
    hideTopAndButtom();
    double tradeWidth = 290;
    return Scaffold(
      backgroundColor: Color.fromRGBO(242, 244, 247, 1),
      body: Column(
        children: [
          Stack(
            alignment: Alignment.center,
            overflow: Overflow.visible,
            children: [
              Container(
                alignment: AlignmentDirectional(-0.7, -0.64),
                height: 400,
                color: myColor,
                child: Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        "15:60",
                        style: TextStyle(fontSize: 64, color: Colors.white),
                      ),
                      SizedBox(width: 5),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(
                            "01-08",
                            style: TextStyle(fontSize: 20, color: Colors.white),
                          ),
                          Text(
                            "星期三",
                            style: TextStyle(fontSize: 20, color: Colors.white),
                          ),
                        ],
                      )
                    ],
                  ),
                  constraints: BoxConstraints(
                    maxHeight: 200,
                    maxWidth: 300,
                    minWidth: 150,
                    minHeight: 150,
                  ),
                ),
              ),
              Positioned(
                  left: (MediaQuery.of(context).size.width / 2) -
                      (tradeWidth / 2),
                  top: 190,
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(20),
                      color: Colors.white,
                    ),
                    alignment: Alignment.center,
                    constraints: BoxConstraints(
                      maxWidth: tradeWidth,
                      maxHeight: tradeWidth + 50,
                      minWidth: tradeWidth,
                      minHeight: tradeWidth + 50,
                    ),
                    child: GestureDetector(
                      behavior: HitTestBehavior.opaque,
                      onTap: () {
                        Navigator.of(context).push(_createRoute(TradePage()));
                      },
                      child: Center(
                        child: Column(
                          children: [
                            SizedBox(
                              height: 45,
                            ),
                            Image.asset(
                              UIData.priceIcon,
                              width: 150,
                              height: 150,
                            ),
                            SizedBox(
                              height: 20,
                            ),
                            Text("定价/定额收银",
                                style: TextStyle(
                                    fontSize: 28,
                                    color: Color.fromRGBO(72, 78, 99, 1),
                                    fontWeight: FontWeight.bold))
                          ],
                        ),
                      ),
                    ),
                  )),
              Positioned(
                  top: 10,
                  left: 10,
                  child: GestureDetector(
                      onLongPress: () {
                        Navigator.of(context).push(_createRoute(SettingPage()));
                      },
                      child:
                          Image.asset(UIData.logoIcon, width: 50, height: 40))),
            ],
          ),
          Container(
            height: 130,
            width: 700,
            margin: EdgeInsets.only(top: 170),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(15)),
            ),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                GestureDetector(
                  onTap: () { Navigator.of(context).push(_createRoute(FlipDemo()));},
                  child: IconText(
                    "营业总汇",
                    icon: Icon(Icons.library_books),
                    style: TextStyle(color: Color.fromRGBO(72, 78, 99, 1)),
                    iconSize: 50,
                    direction: Axis.vertical,
                  ),
                ),
                IconText(
                  "卡查询",
                  style: TextStyle(color: Color.fromRGBO(72, 78, 99, 1)),
                  icon: Icon(Icons.credit_card),
                  iconSize: 50,
                  direction: Axis.vertical,
                ),
                IconText(
                  "订单管理",
                  style: TextStyle(color: Color.fromRGBO(72, 78, 99, 1)),
                  icon: Icon(Icons.assessment),
                  iconSize: 50,
                  direction: Axis.vertical,
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

  Route _createRoute(Widget page) {
    return PageRouteBuilder(
      transitionDuration: Duration(milliseconds: 1000), //动画时间为500毫秒
      pageBuilder: (context, animation, secondaryAnimation) => page,

      transitionsBuilder: (context, animation, secondaryAnimation, child) {
        var begin = Offset(7.0, 5.0);
        var end = Offset.zero;
        var curve = Curves.ease;

        var tween =
            Tween(begin: begin, end: end).chain(CurveTween(curve: curve));

        return SlideTransition(
          position: animation.drive(tween),
          child: child,
        );
      },
    );
  }
}
